package day05;

import java.util.Scanner;

public class test4 {
public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // 获取用户输入
        System.out.print("请输入年份: ");
        int year = scanner.nextInt();
        System.out.print("请输入月份: ");
        int month = scanner.nextInt();
        System.out.print("请输入日期: ");
        int day = scanner.nextInt();
        
        // 计算天数
        int dayOfYear = calculateDayOfYear(year, month, day);
        System.out.printf("%d年%d月%d日是该年的第%d天\n", year, month, day, dayOfYear);
        
        scanner.close();
    }
    
    // 计算一年中的第几天
    private static int calculateDayOfYear(int year, int month, int day) {
        int[] daysInMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        
        // 处理闰年（2月有29天）
        if (isLeapYear(year)) {
            daysInMonth[2] = 29;
        }
        
        // 计算总天数
        int totalDays = day;
        for (int i = 1; i < month; i++) {
            totalDays += daysInMonth[i];
        }
        return totalDays;
    }
    
    // 判断闰年
    private static boolean isLeapYear(int year) {
        return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
    }
}
